﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace ExamText
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var user = TextBox1.Text.Trim();
            var pwd = TextBox2.Text.Trim();
            string sql= "select * from Users where Username='"+user+"'";

            DataTable table = DbHelper.GetDataTable(sql);

            if (table.Rows.Count == 1)
            {
                if (!(bool)table.Rows[0].ItemArray[4])
                {
                    if ((bool)table.Rows[0].ItemArray[3])
                    {
                        if (table.Rows[0].ItemArray[2].ToString() == pwd)
                        {
                            Label4.Visible = false;
                            Response.Redirect("/Default.aspx");
                        }
                        else
                        {
                            Label4.Text = "密码错误，请重试";
                            Label4.Visible = true;
                        }
                    }
                    else
                    {
                        Label4.Text = "用户名已被禁用，请联系管理员";
                        Label4.Visible = true;
                    }
                }
                else
                {
                    Label4.Text = "用户名已被删除，请联系管理员";
                    Label4.Visible = true;
                }
            }
            else
            {
                Label4.Text = "用户名从未注册过，请去注册";
                Label4.Visible = true;
            }
        }
    }
}